/*
 Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
 Original sources are available at www.latestbit.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 TCPConnector.hpp. Created on: 20.08.2009 15:37:40
 */

#ifndef TCPCONNECTOR_HPP_
#define TCPCONNECTOR_HPP_

#include "TCPSharedResources.hpp"
#include "smartobjects/SmartObjectsDefs.hpp"
#include "smartobjects/network/IConnector.hpp"
#include "TCPConnection.hpp"

namespace smartobjects {

class TCPConnector : public virtual TCPConnection, public virtual IConnector {
public:
	SO_DLLPRFX TCPConnector(TCPSharedResources::SharedPtr);
	SO_DLLPRFX virtual ~TCPConnector();
	SO_DLLPRFX virtual void connect(void) throw (const IOException&);
	SO_DLLPRFX virtual void connectAsync(void) throw (const IOException&);
	SO_DLLPRFX virtual void setEndpointURI(URI*) throw (const IOException&) ;
	SO_DLLPRFX virtual void close(void);
	SO_DLLPRFX virtual bool isAcceptorConnection();
protected:
	SO_DLLPRFX virtual void fireOnConnected();
	SO_DLLPRFX virtual void fireOnConnectionFailure(const std::string& sErrorMessage);
private:
	void prepareToConnect() throw (const IOException&);
	void onConnect(bool bStatus) throw();

};

}

#endif /* TCPCONNECTOR_HPP_ */
